package com.csf.client.pipeline;

import javax.net.ssl.SSLEngine;

import static org.jboss.netty.channel.Channels.pipeline;

import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.handler.ssl.SslHandler;

import com.csf.client.decoder.ProtoBuffDeserialiser;
import com.csf.client.encoder.ProtoBuffSerialiser;
import com.csf.common.decoder.HeaderLengthBasedFrameDecoder;
import com.csf.core.ssl.client.ClientSSLContextFactory;

public class PipeLineFactory implements ChannelPipelineFactory  {


	public ChannelPipeline getPipeline() throws Exception {
		ChannelPipeline pipeline = pipeline();
		
		//ssl support
		SSLEngine engine =
		              ClientSSLContextFactory.getClientContext().createSSLEngine();
        engine.setUseClientMode(true);
		pipeline.addLast("ssl", new SslHandler(engine));
        
		//upstream
		//pipeline.addLast("encoder", new MyEncoder());
		pipeline.addLast("encoder", new ProtoBuffSerialiser());
		//downstream
		pipeline.addLast("framedecoder", new HeaderLengthBasedFrameDecoder());
		pipeline.addLast("messagedecoder", new ProtoBuffDeserialiser());
		return pipeline;
	}
	
}
